package com.example.mymvp_2.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mymvp_2.Bean.Weather;
import com.example.mymvp_2.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.MyViewHolder> {
    private Context context;
    private Weather mData;

    public MyRecyclerViewAdapter(Context context, Weather mData) {
        this.context = context;
        this.mData = mData;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_item_weather, parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Weather.DataBean dataBean = mData.getData().get(position);
        holder.tv_days.setText(dataBean.getDays());
        holder.tv_week.setText(dataBean.getWeek());
        holder.tv_temperature.setText(dataBean.getTemperature());
        holder.tv_wind.setText(dataBean.getWind());
        holder.tv_weather.setText(dataBean.getWeather());
        holder.tv_citynm.setText(mData.getCitynm());
        Picasso.with(context).load(dataBean.getWeather_icon()).into(holder.img);
    }

    @Override
    public int getItemCount() {
        return mData.getData().size();
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_days,tv_week,tv_temperature,tv_weather,tv_wind,tv_citynm;
        private ImageView img;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_days=itemView.findViewById(R.id.tv_days);
            tv_week=itemView.findViewById(R.id.tv_week);
            tv_temperature=itemView.findViewById(R.id.tv_temperature);
            tv_weather=itemView.findViewById(R.id.tv_weather);
            tv_wind=itemView.findViewById(R.id.tv_wind);
            tv_citynm=itemView.findViewById(R.id.tv_citynm);
            img=itemView.findViewById(R.id.img_weather_icon);
        }
    }
}
